package com.yanqu.road.server.cmd.activity.seacraftsouthsea;

import com.yanqu.road.entity.activity.seacraft.config.SeacraftSouthSeaFloorConfig;
import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.pb.activity.SeacraftSouthSeaProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.gameplayer.module.player.PreReduceModule;
import com.yanqu.road.server.manger.activity.seacraft.SeacraftSouthSeaMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

/**
 * @Description
 * @Author cwq
 * @Data 2022/1/20 15:28
 */
@Cmd(code = GameProtocol.S_SEACRAFT_SOUTH_SEA_OPEN_PUB_FROM_CROSS, desc = "海上争霸 南海丝路 功勋酒馆挖宝 跨服返回区服 协议")
public class SeacraftSouthOpenPubFromCrossCmd extends AbstractCommand {
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        SeacraftSouthSeaProto.SeacraftSouthSeaOpenPubCrossToGameMsg crossToGameMsg = SeacraftSouthSeaProto.SeacraftSouthSeaOpenPubCrossToGameMsg.parseFrom(packet.getBytes());
        // 取消预扣除
        Property consume = PropertyHelper.parseStringToProperty(crossToGameMsg.getPreConsume());
        player.getModule(PreReduceModule.class).restorePreReduce(consume);
        SeacraftSouthSeaProto.SeacraftSouthSeaOpenPubRespMsg.Builder stcMsg = crossToGameMsg.getStcMsg().toBuilder();
        if (stcMsg.getRet() == 0) {
            // 扣道具
            player.getModule(CurrencyModule.class).removeCurrency(consume, eLogMoneyType.SeacraftActivity, eLogMoneyType.SeacraftActivityOpenPubCost);
            // 加道具
            Property reward = PropertyHelper.parseStringToProperty(crossToGameMsg.getStcMsg().getReward());
            player.getModule(CurrencyModule.class).addCurrency(reward, eLogMoneyType.SeacraftActivity, eLogMoneyType.SeacraftActivityOpenPubReward);
        }
        player.sendPacket(ClientProtocol.U_SEACRAFT_SOUTH_SEA_OPEN_PUB, stcMsg);
    }

    @Override
    public void sendData(GamePlayer player) {
    }
}
